package com.om.common;

import java.sql.Connection;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

import com.om.base.BeanFactory;
import com.om.base.DBConnectionManager;

public class ConnectionListener implements ServletRequestListener {

	
	public void requestDestroyed(ServletRequestEvent r) {
		Connection con;
		try {
			DBConnectionManager.getInstance().freeThreadOpenedConnections(
					Thread.currentThread().hashCode());
			if (r.getServletRequest().getAttribute("opened_conn") != null) {
				r.getServletRequest().removeAttribute("opened_conn");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}


	// @Override
	public void requestInitialized(ServletRequestEvent e) {
		try {
			if(TaskConnectionManage.ConnectionManageClass==null){
				TaskConnectionManage.ConnectionManageClass = TaskConnectionManage.class;
			}
			
			if(BeanFactory.BeanFactoryClass  == null){
				BeanFactory.BeanFactoryClass = MySqlBeanFactory.class;
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

}
